import { apiUnreadMsg } from '@/api/message'
import Vue from 'vue'

export default function setMsgStatus(isShow = false) { 
	if(!isShow) {
		clearInterval(Vue.prototype.$store.getters.msgTimer)
	}else {
		if(Vue.prototype.$store.getters.msgTimer) clearInterval(Vue.prototype.$store.getters.msgTimer)
		let timer = setInterval(function() {
			apiUnreadMsg().then(res => {
				if(res.data.unread_count !== null && res.data.unread_count > 0) {
					uni.showTabBarRedDot({
						index: 3
					})
				} else {
					uni.hideTabBarRedDot({
						index: 3
					})
				}
			}).catch( () => {
				console.log('error')
			})
		},30000)
		Vue.prototype.$store.dispatch('message/setMsgTimer', timer)
	}
}